from rest_framework import serializers

from DRFApis.models import UserProfile, UserAddress


# class UserSerializer(serializers.Serializer):
#     """
#     使用serializers.Serializer
#     """
#     username = serializers.CharField(max_length=150)
#     name = serializers.CharField(max_length=30)
#     birthday = serializers.DateField()
#     gender = serializers.CharField(max_length=6)
#     mobile = serializers.CharField(max_length=11)
#     email = serializers.EmailField(max_length=100)
#
#     def create(self, validated_data):
#         return UserProfile.objects.create(**validated_data)


class UserSerializer(serializers.ModelSerializer):
    """
    使用serializers.ModelSerializer
    """
    class Meta:
        model = UserProfile
        # fields = ['username', 'name', 'birthday', 'gender', 'mobile', 'email']
        fields = "__all__"


class UserAddressSerializer(serializers.ModelSerializer):
    """
    一并查询外键
    """
    user = UserSerializer()

    class Meta:
        model = UserAddress
        fields = "__all__"



